from django.db import models
from structures import Position
from base import TimeRelation
from core import Person
from structures import Institution

class Elections(models.Model):
    '''
    Single election cycle
    '''
    name = models.CharField(max_length=150, blank=True, default='YYYY Elections for X')
    date = models.DateField()
    slug = models.SlugField()
    position = models.ForeignKey(Position, related_name="elections")

    class Meta:
        verbose_name_plural = 'Elections'
        app_label = 'openpolitics'

    def __unicode__(self):
        return self.name

class Candidate(TimeRelation):
    '''
    A person or institution
    which is a candidate in a given elections
    '''
    elections = models.ForeignKey(Elections)

    class Meta:
        abstract = True
        app_label = 'openpolitics'

    def __unicode__(self):
        return self.candidate.name

class PersonCandidate(Candidate):
    '''
    A person candidate in a given elections
    '''
    candidate = models.ForeignKey(Person)

    class Meta:
        app_label = 'openpolitics'

class InstitutionCandidate(Candidate):
    '''
    An institutional candidate in a given elections
    (example: a party)
    '''
    candidate = models.ForeignKey(Institution)

    class Meta:
        app_label = 'openpolitics'
